<template>
    <div>
        <div class="title" v-if="isImage">
            <img :src="props.src" />
        </div>
        <div class="title2" v-else>
            {{ props.number }}
        </div>
    </div>
</template>
<script lang="ts">
export default {
    name: "XEvent",
};
</script>

<script lang="ts" setup>
import {ref,onMounted,watch,onUpdated} from 'vue'
const props = defineProps({
    src: {
        type: String,
        required:true
    },
    number: {
        type: String,
        required:true
    }
})
const isImage=ref(false)
const checkImgExists=(imgurl:string) =>{
  try{
    var ImgObj = new Image();
    ImgObj.src = imgurl;
    ImgObj.onload = () => {
      isImage.value = true;
    };
    ImgObj.onerror = () => {
 
      isImage.value= false;
    };
  }catch(error){
    console.log('error')
  }
 
  }
  onUpdated(()=>{
    setTimeout(()=>{
        checkImgExists(props.src)
    },1000)
  })
  onMounted(()=>{
      setTimeout(()=>{
        checkImgExists(props.src)
    },1000)
  })


</script>
<style lang="scss" scoped>
.title {
    background-color: #fff;
    height: 190px;
    line-height: 120px;
    font-size: 40px;
    color: #fff;
    overflow: hidden;
    position: relative;
    font-family: 'Calibri';
    img {
        height: 100%;
        width: 100%;
        object-fit: cover;
        // position: absolute;
        // top: 50%;
        // left: 50%;
        // transform: translate(-50%, -50%);
    }
}
.title2 {
    background-color: #23445a;
    color: #fff;
    height: 190px;
    line-height: 190px;
    font-size: 40px;
    text-align: center;
}
</style>

<style lang="scss" scoped>
@media (min-width: 768px) and (max-width: 1400px) {
    .title {
        height: calc(100vw / var(--screen) * 190);
        line-height: calc(100vw / var(--screen) * 120);
        font-size: calc(100vw / var(--screen) * 40);
    }
    .title2 {
        height: calc(100vw / var(--screen) * 190);
        line-height: calc(100vw / var(--screen) * 190);
        font-size: calc(100vw / var(--screen) * 40);
    }
}
</style>